home *** CD-ROM | disk | FTP | other *** search
- /**
- --
- -- App: Getting Started w/QD GX (WWDC)
- --
- --
- -- Version: 1.0 4/93: added all of the calls required to support the "Getting
- -- Started with QuickDraw™ GX" session at the WWDC '93
- --
- -- 8/93: updated file to work with the ß2 "GXified" interface files
- -- 9/93: now overrides gxPrintingEvent for update event handling.
- -- added GXUpdateJob call to resume event handling. - dmh
- -- 5/94: gxPrintingEvent override now ignores appropriate events. - dmh
- --
- -- 4/96 bob Updated #includes to support changed GX Library names.
- -- Updated the note regarding the files needed to run.
- -- Updated the copyright date.
- --
- -- File: Getting Started GX - main.c
- --
- --
- -- Comments: This file is a part of a shell that can be used to build QuickDraw GX
- -- applications. It contains all of the required calls to: testing for
- -- QuickDraw GX, gxInitialize the QuickDraw GX world, and handling events.
- --
- -- For this shell to work correctly, it expects the following functions to
- -- be defined:
- --
- -- void DoInitialization(WindowPtr);
- -- void DoDraw(WindowPtr);
- -- void DoDispose(WindowPtr);
- -- void DoClick(WindowPtr);
- -- void DoIdle(WindowPtr);
- --
- -- By the way, if the QuickDraw GX printing system is not installed, we will
- -- not enable the print menu items in th File menu. The app will still draw
- -- QuickDraw GX shapes to the window, but it will not print them.
- --
- --
- --
- -- Components: Getting Started GX - main.c
- -- Getting Started GX - main.h
- -- Getting Started GX - shapes.c
- -- Getting Started GX - printing.c
- -- Getting Started GX - misc.c
- -- Getting Started QD GX.π.rsrc
- --
- -- The file titled: "Getting Started GX - main.c" contains the code required to
- -- intialize and tear down the QuickDraw GX world, and the event loop.
- --
- -- The file titled: "Getting Started GX - shapes.c" contains of the code used to
- -- create and manipulate the shapes draw into the window.
- --
- -- The file titled: "Getting Started GX - printing.c" contains of the code used to
- -- print the contents of the window.
- --
- -- The file titled: "Getting Started GX - misc.c" contains of the code for the utilities used.
- --
- --
- -- QuickDraw GX
- -- Libraries
- -- Used: This application uses the following QuickDraw GX library code files:
- -- "ColorLibrary.c", "FontLibrary.c", "GraphicsDebugLibrary.c", "LayoutLibrary.c",
- -- "ShapeLibrary.c", "TransferModeLibrary.c", and "TransformLibrary.c".
- --
- --
- -- Notes: 1) Print this file in landscape for the best results
- -- 2) If you are using THINK C v5.x, I have added THINK markers to navigate the code.
- -- 3) This code was adapted from the "Banana Jr." QuickDraw GX sample.
- --
- --
- -- Author: Pete "Luke" Alexander
- -- Developer Technical Support
- -- AppleLink: DEVSUPPORT
- --
- --
- -- ©1990 - 1996 Apple Computer, Inc.
- -- All rights reserved.
- --
- **/
-
-
- #include <Desk.h>
- #include <Events.h>
- #include <Fonts.h>
- #include <Windows.h>
- #include <Memory.h>
- #include <ToolUtils.h>
- #include <Menus.h>
- #include <Quickdraw.h>
-
- #include <GXPrinting.h>
- #include <GXEnvironment.h>
- #include <GXGraphics.h>
- #include "GraphicsLibraries.h"
- #include <GXErrors.h>
- #include "Getting Started GX - main.h"
-
- #define kOSEvent app4Evt /* event used by MultiFinder */
- #define kSuspendResumeMessage 1 /* high byte of suspend/resume event message */
- #define kResumeMask 1 /* bit of message field for resume vs. suspend */
-
- Boolean gQuitting;
-
- gxStyle gOurStyle;
- gxColor gTextColor;
- gxTransform gRotatedTransform;
- gxPoint gTextLocation = {ff(75), ff(105)};
- long gSleep = 0;
-
- /*------ main -----------------------------------------------------------------------------------------*/
-
- void main()
- {
- CursHandle theCurs;
- Handle menuBar;
- gxGraphicsClient client;
- OSErr err;
- WindowPtr wind;
-
- /**
- The GXNewGraphicsClient routine defines the graphics heap size. If you do not make this call,
- the GX graphics engine will create this heap automatically. How? It will create a heap which
- is a percentage of your application's ideal memory foot print. This call allows you to explicity
- define the ammount of memory used by the graphics system for it's graphics objects heap.
- **/
- client = GXNewGraphicsClient(nil, gGraphicsHeapSize * 1024, 0L);
-
- /** Generic heap initialization. **/
- MaxApplZone();
- MoreMasters(); MoreMasters(); MoreMasters();
- MoreMasters(); MoreMasters(); MoreMasters();
-
- /**
- If gDebugging = TRUE, you will receive graphics library errors & notices will be posted. This
- functionality will only work with the "debugging" version of the QuickDraw GX init. If this
- init is not installed, these functions will not work.
- **/
- if (gDebugging) {
- SetGraphicsLibraryErrors ();
- SetGraphicsLibraryNotices();
- }
-
- /**
- Set "gGiveMeValidation" to TRUE, if you want run-time validation. As you increase the amount
- of validation, The drawing speed will SLOW down due to all of the internal checking.
-
- publicValidation will check parameters to public routines. For additional details regarding
- the various levels of validation, please see the documentation.
- **/
- if (gGiveMeValidation) GXSetValidation(gxPublicValidation);
-
-
- /** initialize the new graphics and printing environments. **/
-
- GXEnterGraphics();
- err = GXInitPrinting();
-
- /** initialize the other managers, if no errors occured. **/
-
- if (!err)
- {
- InitGraf(&qd.thePort);
- InitFonts();
- InitWindows();
- InitMenus();
- InitCursor();
-
- theCurs = GetCursor(watchCursor);
- SetCursor(*theCurs);
-
- menuBar = GetNewMBar(rMenuBar); /* Create the menu bar */
-
- if (menuBar)
- {
- gQuitting = false;
- SetMenuBar(menuBar);
- DisposHandle(menuBar);
- AddResMenu(GetMHandle(mApple), 'DRVR'); /* add Apple Menu items */
- DrawMenuBar();
-
- // We initialize the CommonColors Library. This will allow us to set the color of a
- // shape by calling the SetShapeCommonColor function. We will need to call
- // DisposeCommonColors when we leave, to clean up the world.
-
- InitCommonColors();
-
- DoCreateNew();
- SetCursor(&qd.arrow);
-
- while (!gQuitting)
- {
- EventLoop();
- DoIdle(wind);
- }
-
-
- // Leaving. Close all the windows so we get rid of any data we or GX created. Then,
- // dispose of the common colors and exit the GX printing and graphics environment.
-
- while (wind = FrontWindow())
- DoDispose(wind);
-
- DisposeCommonColors();
- if (gOurStyle != nil) GXDisposeStyle (gOurStyle);
- if (gRotatedTransform != nil) GXDisposeTransform (gRotatedTransform);
- }
-
- GXExitPrinting(); /** Close the new printing mgr. **/
- }
-
- GXExitGraphics(); /** Deallocate all of the default structures **/
- GXDisposeGraphicsClient(client);
- }
-
-
- /*------ MyPrintingEventOverride -----------------------------------------------------------------------------*/
- // Override for GXPrintingEvent. It allows us to update our windows
- // when the moveable modal printing dialogs are moved.
-
- OSErr MyPrintingEventOverride(EventRecord *anEvent, Boolean filterEvent)
- {
- OSErr err = noErr;
-
- // Handle events in whatever way is appropriate. MyDoEvent is our
- // generic event handler. We don't pass it events that it shouldn't
- // handle while print dialogs are displayed.
-
- if (!filterEvent)
- switch (anEvent->what)
- {
- case mouseDown:
- case keyDown:
- case autoKey:
- break;
-
- default:
- MyDoEvent(anEvent);
- }
-
- return err;
- }
-
-
- /*------ EventLoop ------------------------------------------------------------------------------------*/
-
- void EventLoop()
- {
- EventRecord theEvent;
-
- if (WaitNextEvent(everyEvent, &theEvent, gSleep, nil))
- MyDoEvent(&theEvent);
- }
-
-
-
- /*------ MyDoEvent ------------------------------------------------------------------------------------*/
-
- void MyDoEvent(EventRecord *theEvent)
- {
- char key;
- WindowPtr whichWindow;
- GrafPtr oldPort;
-
- switch(theEvent->what)
- {
- case updateEvt:
- if (((WindowPeek) theEvent->message)->windowKind == userKind)
- {
- GetPort(&oldPort);
- SetPort((WindowPtr) theEvent->message);
- BeginUpdate((WindowPtr) theEvent->message);
- DoDraw((WindowPtr) theEvent->message);
- EndUpdate((WindowPtr) theEvent->message);
- SetPort(oldPort);
- }
- break;
-
- case mouseDown:
- switch (FindWindow(theEvent->where, &whichWindow)) {
- case inSysWindow:
- SystemClick(theEvent, whichWindow);
- break;
-
- case inDrag:
- if (((WindowPeek) whichWindow)->windowKind == userKind)
- DragWindow(whichWindow, theEvent->where, &qd.screenBits.bounds);
- break;
-
- case inGoAway:
- if (((WindowPeek) whichWindow)->windowKind == userKind)
- {
- if (TrackGoAway(whichWindow, theEvent->where))
- DoDispose(whichWindow);
- }
- break;
-
- case inContent:
- if ((whichWindow != FrontWindow()) &&
- (((WindowPeek) whichWindow)->windowKind == userKind))
- SelectWindow(whichWindow);
- break;
- case inMenuBar:
- DoMenuCommand(MenuSelect(theEvent->where));
- break;
-
- }
-
- case keyDown:
- case autoKey:
- key = theEvent->message & charCodeMask;
- if (theEvent->modifiers & cmdKey)
- if (theEvent->what == keyDown)
- DoMenuCommand(MenuKey(key));
- break;
-
-
- case kOSEvent:
- switch ((unsigned long) theEvent->message >> 24) { /** high byte of message **/
- case kSuspendResumeMessage: /** suspend/resume is also an activate/deactivate **/
- if ((theEvent->message & kResumeMask) == 0)
- gSleep = 80; /** we are headed to the background, so slow down... **/
- else
- {
- gSleep = 0; /** we are headed to the foreground, so speed up... **/
-
- // On a resume event, we need to call GXUpdateJob on all of our documents'
- // jobs. This is important because the user may have just changed
- // something which affects our jobs (like the size of the paper in the
- // printer).
- //
- // Since our application stores our document references in the refCon fields
- // of our documents' windows, we just loop through every one of our windows,
- // extract our document pointers and update the associated jobs.
-
- whichWindow = FrontWindow();
-
- while (whichWindow != nil)
- {
- if (((WindowPeek) whichWindow)->windowKind == userKind)
- GXUpdateJob(GetDocJob(whichWindow));
-
- whichWindow = (WindowPtr) ((WindowPeek) whichWindow)->nextWindow;
- }
- }
- break;
- }
- break;
- }
- }
-
-
-